<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<h1>Tenants</h1>

<h4>
  Copy/paste the tenant's id to the API gateway configuration file in order to resolve API endpoints according to the configured tenant.
</h4>

<div class="add-button-container" *gioPermission="{ anyOf: ['organization-tenant-c'] }">
  <button (click)="onAddTenantClicked()" mat-raised-button color="primary" aria-label="Button to add a tenant" data-testid="add-tenant">
    <mat-icon>add</mat-icon>Add a tenant
  </button>
</div>

<gio-table-wrapper [length]="tenantsTableUnpaginatedLength" (filtersChange)="onFiltersChanged($event)">
  <table mat-table [dataSource]="tenantsDataSource" class="tenants-table" id="tenantsTable" aria-label="Tenant table">
    <!-- Id Column -->
    <ng-container matColumnDef="id">
      <th mat-header-cell *matHeaderCellDef id="id">Id</th>
      <td mat-cell *matCellDef="let element">{{ element.id }}</td>
    </ng-container>

    <!-- Name Column -->
    <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef id="name">Name</th>
      <td mat-cell *matCellDef="let element">{{ element.name }}</td>
    </ng-container>

    <!-- Description Column -->
    <ng-container matColumnDef="description">
      <th mat-header-cell *matHeaderCellDef id="description">Description</th>
      <td mat-cell *matCellDef="let element">{{ element.description }}</td>
    </ng-container>

    <!-- Actions Column -->
    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef id="actions"></th>
      <td mat-cell *matCellDef="let element">
        <div class="centered-cell">
          <ng-container *gioPermission="{ anyOf: ['organization-tenant-u'] }">
            <button
              (click)="onEditTenantClicked(element)"
              mat-icon-button
              aria-label="Button to edit a tenant"
              matTooltip="Edit tenant"
              data-testid="edit-tenant"
            >
              <mat-icon>edit</mat-icon>
            </button>
          </ng-container>
          <ng-container *gioPermission="{ anyOf: ['organization-tenant-d'] }">
            <button
              (click)="onDeleteTenantClicked(element)"
              mat-icon-button
              aria-label="Button to delete a tenant"
              matTooltip="Delete tenant"
              data-testid="delete-tenant"
            >
              <mat-icon>delete</mat-icon>
            </button>
          </ng-container>
        </div>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>

    <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
      <td class="mat-mdc-cell mdc-data-table__cell" colspan="4">No tenant</td>
    </tr>
  </table>
</gio-table-wrapper>
